package server.main.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import server.main.config.BeanInsert.Beans.PermissionRefresh;
import server.main.mapper.PermissionMapper;
import server.main.pojo.Permission;
import server.main.service.PermissonService;


import java.security.Permissions;
import java.util.HashMap;
import java.util.Map;

/**
 * @auther MingHsZzz
 * @Date 2022/9/18  13:39
 * @project main
 * @description
 */



@RequestMapping("/permission")
@RestController
public class PermissionController {

   @Autowired
   PermissionRefresh permissionRefresh;
   @Autowired
   PermissonService permissonService;


   @GetMapping("/getrole")
   public Map<String,Object> getrole(){
      Map<String,Object> map = new HashMap<>();
      return map;
   }

   @GetMapping("/getallpermission")
   public Map<String,Object> getPermission(){
      Map<String,Object> map = new HashMap<>();
      map.put("code",200);
      map.put("data",permissonService.getAllpermissions());
      System.out.println(map);
      return map;
   }


   @GetMapping
   public Map<String,Object> getAllPermissionWithPage(@RequestParam(required = false, defaultValue = "") String permissionName,
                                                      @RequestParam(required = false, defaultValue = "1") Integer pageNum,
                                                      @RequestParam(required = false, defaultValue = "10") Integer pageSize){

      Map<String,Object> map = new HashMap<>();


      Page<Permission> allpermissionByPage = permissonService.getAllpermissionByPage(permissionName,pageNum,pageSize);


      map.put("code",200);
      map.put("data",allpermissionByPage);
      System.out.println(allpermissionByPage.getRecords());
      return map;



   }









}
